#include "GlobalLog.h"
#include "../cfg/GlobalCfg.h"
#include "../3rdparty/Log/Include/QsLog.h"
#include "../3rdparty/Log/Include/QsLogLevel.h"
#include "QTextCodec.h"

using namespace QsLogging;
#pragma comment(lib,"3rdparty/Log/Lib/QsLog2.lib")

GlobalLog::GlobalLog()
{


}

void GlobalLog::InitInstance()
{
	GlobalLog::getInstance().m_Coder = QTextCodec::codecForName("GBK");


	Logger& logger = Logger::instance();
	logger.setLoggingLevel(QsLogging::TraceLevel);
	QString dir = QCoreApplication::applicationDirPath() + "/log.txt";
	const QString sLogPath(dir);

	// 2. add two destinations
	DestinationPtr fileDestination(DestinationFactory::MakeFileDestination(sLogPath, EnableLogRotation, MaxSizeBytes(1024*1024*GlobalCfg::getInstance().m_LogCfg.iMaxFileSize_M), MaxOldLogCount(GlobalCfg::getInstance().m_LogCfg.iMaxFileCount)));
	//DestinationPtr debugDestination(DestinationFactory::MakeDebugOutputDestination());
	//DestinationPtr functorDestination(DestinationFactory::MakeFunctorDestination(&logFunction));
	//logger.addDestination(debugDestination);
	logger.addDestination(fileDestination);
	//logger.addDestination(functorDestination);
}


void GlobalLog::WriteErrorLog(QString strLog, bool bNeedCodec)
{
	QLOG_ERROR() << strLog;
}


void GlobalLog::WriteInfoLog(QString strLog, bool bNeedCodec)
{
	QLOG_WARN() << strLog;
}